package cn.robot.board;

import android.content.ComponentName;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.pdf.PdfDocument;
import android.media.MediaScannerConnection;
import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;

import org.json.JSONObject;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.robot.board.greendao.DataBaseBean;
import cn.robot.board.net.CallBackListener;
import cn.robot.board.net.RbtCloud;
import cn.robotpen.model.entity.note.BlockEntity;
import cn.robotpen.model.entity.note.NoteEntity;
import cn.robotpen.model.entity.note.TrailsEntity;
import cn.robotpen.model.symbol.DeviceType;
import cn.robotpen.pen.callback.RobotPenActivity;
import cn.robotpen.pen.model.RemoteState;
import cn.robotpen.pen.model.RobotDevice;
import cn.robotpen.pen.model.RobotPoint;
import cn.robotpen.pen.model.matrix.OriginalPosition;
import cn.robotpen.views.utils.PointAndW;
import cn.robotpen.views.widget.PenTrajectoryView;
import wang.relish.colorpicker.ColorPickerDialog;

public class SimpleBoardActivity extends RobotPenActivity implements View.OnClickListener, PenTrajectoryView.PenTrajectoryInterface {
    private String TAG = "robot";
    DeviceType mDeDeviceType = DeviceType.L8;
    String     mNoteKey      = NoteEntity.KEY_NOTEKEY_TMP;
    int        isRubber;//是否是橡皮大于0算是橡皮
    float      mPenWeight    = 50;//笔粗细(0.1毫米)
    int        mPenColor     = Color.BLACK;//笔颜色

    private CheckBox          cb_rubber;
    private View              v_color;
    private TextView          tv_pen_width;
    private PenTrajectoryView penTrajectoryView;
    private LinearLayout      rl_content_root;

    private List<TrailsEntity> playbackTrails = new ArrayList<>();
    OriginalPosition[] criterions = new OriginalPosition[2];
    private List<OriginalPosition> pointListOne = new ArrayList<>();
    private List<OriginalPosition> pointListTwo = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple_board);
        //屏幕常亮控制
        this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        initView();
    }

    @Override
    protected void onStart() {
        super.onStart();
        rl_content_root.post(new Runnable() {
            @Override
            public void run() {
                int uiPortHeight = rl_content_root.getMeasuredHeight();
                ViewGroup.LayoutParams params = penTrajectoryView.getLayoutParams();
                params.width = uiPortHeight * 559 / 794;
                params.height = uiPortHeight;
                LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(params.width, params.height);
                llp.gravity = Gravity.CENTER;
                penTrajectoryView.setLayoutParams(llp);
            }
        });
    }

    private void initView() {
        rl_content_root = (LinearLayout) findViewById(R.id.rl_content_root);
        penTrajectoryView = (PenTrajectoryView) findViewById(R.id.penTrajectoryView);
        penTrajectoryView.setIsTouchWrite(true);//默认用手输入
        penTrajectoryView.setLoadIgnorePhoto(false);
        // 画布背景图
        penTrajectoryView.setBackgroundResource(R.mipmap.bg_a5);
        penTrajectoryView.setPlaySpeed(0.5);//设置播放速度
        penTrajectoryView.initDrawArea();

        cb_rubber = (CheckBox) findViewById(R.id.cb_rubber);
        v_color = findViewById(R.id.v_color);
        tv_pen_width = (TextView) findViewById(R.id.tv_pen_width);
        SeekBar sb_pen_width = (SeekBar) findViewById(R.id.sb_pen_width);

        findViewById(R.id.btn_empty).setOnClickListener(this);
        cb_rubber.setOnClickListener(this);
        v_color.setOnClickListener(this);
        findViewById(R.id.btn_playback).setOnClickListener(this);
        findViewById(R.id.btn_criterion).setOnClickListener(this);
        findViewById(R.id.btn_count).setOnClickListener(this);
        findViewById(R.id.btn_migration).setOnClickListener(this);

        v_color.setBackgroundColor(mPenColor);
        tv_pen_width.setText("笔粗细:" + (mPenWeight / 100) + "毫米");
        sb_pen_width.setProgress((int) mPenWeight);
        sb_pen_width.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                tv_pen_width.setText("笔粗细:" + ((float) progress / 100) + "毫米");
                mPenWeight = (progress);
                setOptimalPointWidth();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_empty://清空
                penTrajectoryView.cleanScreen();
                playbackTrails.clear();
                try {
                    getPenServiceBinder().turnOffCalibration();
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
                break;
            case R.id.cb_rubber://橡皮
                if (cb_rubber.isChecked()) {
                    penTrajectoryView.setIsTouchWrite(true);
                } else {
                    RobotDevice device = null;
                    try {
                        device = getPenServiceBinder().getConnectedDevice();
                        if (device == null) {
                            penTrajectoryView.setIsTouchWrite(true);
                        } else {
                            penTrajectoryView.setIsTouchWrite(false);
                        }
                    } catch (RemoteException e) {
                        e.printStackTrace();
                    }
                }
                break;
            case R.id.v_color://颜色
                new ColorPickerDialog.Builder(SimpleBoardActivity.this, mPenColor)   //mColor:初始颜色
                        .setHexValueEnabled(true)               //是否显示颜色值
                        .setOnColorChangedListener(new ColorPickerDialog.OnColorChangedListener() {
                            @Override
                            public void onColorChanged(int i) {
                                mPenColor = i;
                                v_color.setBackgroundColor(mPenColor);
                            }
                        }) //设置监听颜色改变的监听器
                        .build()
                        .show();//展示

                break;
            case R.id.btn_playback://回放
                if (playbackTrails.size() == 0) {
                    Toast.makeText(SimpleBoardActivity.this, "请先进行书写", Toast.LENGTH_SHORT).show();
                } else {
                    penTrajectoryView.cleanScreen();
                    penTrajectoryView.setIsWrite(false);
                    penTrajectoryView.loadTrails(playbackTrails, true);
                    // penTrajectoryView.loadTrails(playbackTrails, true, true, true);
                }
                break;
            case R.id.btn_criterion:// OCR
                ocrHandler();
                break;
            case R.id.btn_count:
                // 导出到本地
                saveFile();
                break;
            case R.id.btn_migration://计算偏移
                if (pointListOne.size() >= 20 && pointListTwo.size() >= 20) {
                    try {
                        getPenServiceBinder().getCalibrationOffset(pointListOne, pointListTwo);
                    } catch (RemoteException e) {
                        Log.e("asd", "onClick: RemoteException:" + e.toString());
                        e.printStackTrace();
                    }
                }
                break;
        }
    }

    int pageNumber = 0;

    void saveFile() {
        Bitmap trails = penTrajectoryView.getCanvasImage();

        Paint pa = new Paint();
        pa.setAntiAlias(true);
        pa.setFilterBitmap(true);
        pa.setDither(true);

        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.mipmap.bg_a5);
        Bitmap bg = Bitmap.createScaledBitmap(bmp, trails.getWidth(), trails.getHeight(), false);

        PdfDocument document1 = new PdfDocument();
        PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(trails.getWidth(), trails.getHeight(), pageNumber).create();
        PdfDocument.Page page = document1.startPage(pageInfo);
        Canvas canvas = page.getCanvas();
        canvas.drawBitmap(bg, 0, 0, pa);
        canvas.drawBitmap(trails, 0, 0, pa);
        document1.finishPage(page);
        String fName = "rbt_canvas_P" + pageNumber + "_" + System.currentTimeMillis() + ".pdf";
        File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), fName);
        try {
            FileOutputStream fos = new FileOutputStream(f);
            document1.writeTo(fos);
            fos.flush();
            fos.close();
            MediaScannerConnection.scanFile(this, new String[]{f.getAbsolutePath()}, null, null);
        } catch (IOException e) {
            e.printStackTrace();
        }
        Toast.makeText(this, fName + "保存成功，位于Download目录下", Toast.LENGTH_SHORT).show();
    }

    @Override
    public boolean onEvent(PenTrajectoryView.BoardEvent boardEvent, Object object) {
        switch (boardEvent) {
            case TRAILS_COMPLETE: //笔迹加载完成
                penTrajectoryView.setIsWrite(true);
                break;
            case BOARD_AREA_COMPLETE: //白板区域加载完成
                penTrajectoryView.beginBlock();
                break;
            case ERROR_DEVICE_TYPE: //检测到连接设备更换
                break;
            case ERROR_SCENE_TYPE: //横竖屏更换
                break;
            case ON_TRAILS://一笔结束产生一条新的轨迹
                playbackTrails.add((TrailsEntity) object);
                break;
            case ON_TRAILS_CLEAN://笔迹被清
                break;
            case ON_POINT:
                PointAndW p = (PointAndW) object;
                // Log.d(TAG, "ON_POINT: " + p.getMotionEvent().getX() + "," + p.getMotionEvent().getY() + "  W:" + p.getW() + "  P:" + p.getMotionEvent().getPressure());
                break;
        }
        return true;
    }

    // 是否刚换页、重绘历史笔迹中
    boolean changePage = false;

    /**
     * D7设备新协议，增加相对于上一个点的时间间隔
     */
    @Override
    public void onPenPointPaperType(int deviceType, int x, int y, int pressure, byte state, long page, int angle, int latticeType, int timeStamp, String data) {
        super.onPenPointPaperType(deviceType, x, y, pressure, state, page, angle, latticeType, timeStamp, data);
        Log.i(TAG, String.format("onPenPointPaperType x:%s, y:%s, pressure:%s, state:%s, page:%s, angle:%s, timeStamp:%s", x, y, pressure, state, page, angle, timeStamp));
        if (page == 0) {
            return;
        }
        x = x * 210 / 148;
        y = y * 297 / 210;
        if (page != pageNumber) {
            penTrajectoryView.cleanScreen();
            penTrajectoryView.cleanTrail();
            playbackTrails.clear();
            pageNumber = (int) page;
            savePoints(x, y, state, pressure);
            ((TextView) findViewById(R.id.tv_page)).setText("当前页码：" + page);
            penTrajectoryView.drawDevicePoint(DeviceType.toDeviceType(deviceType), x, y, pressure, state, timeStamp);
            changePage = true;
            // 查询并重绘
            List<DataBaseBean> trailsList = MyApplication.daoSession.queryRaw(DataBaseBean.class, " where PAGE = ? ORDER BY _id ASC", pageNumber + "");
            Log.e(TAG, String.format("查询笔迹数据库：当前页：%d, 历史笔迹点数：%d", pageNumber, trailsList.size()));
            for (DataBaseBean b : trailsList) {
                penTrajectoryView.drawDevicePoint(DeviceType.toDeviceType(deviceType), b.getX(), b.getY(), b.getPressure(), (byte) b.getState(), 1);
            }
            changePage = false;
            return;
        } else if (!changePage) {
            penTrajectoryView.drawDevicePoint(DeviceType.toDeviceType(deviceType), x, y, pressure, state, timeStamp);
        }
        // 换页瞬间，笔迹只存储，防止连笔
        savePoints(x, y, state, pressure);
    }

    /**
     * 优化点抛出
     * <p>
     * 此方法与 onPenPositionChanged 方法只能使用其中的一个
     * 可以通过getPenServiceBinder().changeReportOptimalPoint(true)设置使用此方法
     * <p>
     * 独有的优化点绘制方法  penTrajectoryView.onOutputPoint
     *
     * @param width 笔宽度   1.非压力值  2.大于零时表示已落笔，这点和压力值相同
     *              可以通过getPenServiceBinder().setPenPointWidth(mPenWeight)设置优化点的默认笔迹宽度
     */
    @Override
    public void onRemoteOptimalPoint(int deviceType, float x, float y, float width, float speed, int state, int angle, int timeStamp, int latticeType, long pageNumber, String dataAll) {
        super.onRemoteOptimalPoint(deviceType, x, y, width, speed, state, angle, timeStamp, latticeType, pageNumber, dataAll);
        Log.i(TAG, String.format("onRemoteOptimalPoint x:%s, y:%s, width:%s, state:%s, page:%s, angle:%s, timeStamp:%s", x, y, width, state, pageNumber, angle, timeStamp));
        if (pageNumber == 0) {
            return;
        }
        pageNumber = (int) pageNumber;
        ((TextView) findViewById(R.id.tv_page)).setText("当前页码：" + pageNumber);
        x = x * 210 / 148;
        y = y * 297 / 210;
        savePoints(x, y, state, (state == 0 || state == 0x10 ? 0 : (int) (width * 1023 / mPenWeight)));
        if (isRubber == 0) {// isRubber==0  现在没用橡皮察 止选择橡皮擦的时候，不小心触碰笔，绘制笔迹。
            //新增的优化点绘制方法
            penTrajectoryView.onOutputPoint(deviceType, x, y, width, speed, state);
        }
    }

    // 笔迹点入sqlite
    private void savePoints(float x, float y, int state, int pressure) {
        RobotPoint point = new RobotPoint();
        point.setX((int) x);
        point.setY((int) y);
        point.setPressure(pressure);
        point.setState((byte) state);
        checkPointData(point);

        DataBaseBean b = new DataBaseBean();
        b.setX(x);
        b.setY(y);
        b.setState(state);
        b.setPressure(pressure);
        b.setPage(pageNumber);
        MyApplication.daoSession.insert(b);
    }

    //每一笔数据的集合
    Map<Integer, List<RobotPoint>> pMap      = new HashMap<>();
    //笔划计数
    int                            pNum      = 0;
    //上一个点
    RobotPoint                     pointLast = new RobotPoint();

    // OCR识别
    RbtCloud rbtCloud = new RbtCloud();

    private void ocrHandler() {
        //示例做的是单字的识别
        List<Map<String, List<Integer>>> pMapList = new ArrayList<Map<String, List<Integer>>>();
        for (Map.Entry<Integer, List<RobotPoint>> info : pMap.entrySet()) {
            Map<String, List<Integer>> pMap_item = new HashMap<>();
            List<Integer> xList = new ArrayList<Integer>();
            List<Integer> yList = new ArrayList<Integer>();
            for (int t = 0; t < info.getValue().size(); t++) {
                RobotPoint ainfo = info.getValue().get(t);
                xList.add(ainfo.getX());
                yList.add(ainfo.getY());
            }
            pMap_item.put("x", xList);
            pMap_item.put("y", yList);
            pMapList.add(pMap_item);
        }
        Gson gson = new Gson();
        String strokes = gson.toJson(pMapList);
        rbtCloud.trailsRecog(strokes, "zh_CN", new CallBackListener() {
            @Override
            public void onFinish(String result) {
                try {
                    Log.e("test", "response: " + result);
                    JSONObject jRoot = new JSONObject(result);
                    if (jRoot.has("code") && jRoot.getInt("code") == 1) {
                        JSONObject resultObject = new JSONObject(result);
                        JSONObject dataObject = resultObject.optJSONObject("data");
                        String label = dataObject.optString("label");
                        if (!TextUtils.isEmpty(label)) {
                            Log.e("test", "汉字 label: " + label);
                            Toast.makeText(SimpleBoardActivity.this, label, Toast.LENGTH_SHORT).show();
                            // tv_X.setText("汉字:" + label + "");
                        }
                    } else {
                        String err = jRoot.getString("msg");
                        Toast.makeText(SimpleBoardActivity.this, "报错信息：" + err, Toast.LENGTH_SHORT).show();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onError(String e) {
            }
        });
    }

    private void checkPointData(RobotPoint point) {
        //如果是书写过程
        if (pointLast.getPressure() != 0 && point.getPressure() != 0) {
            if (!pMap.containsKey(pNum)) {
                List<RobotPoint> plist = new ArrayList<>();
                pMap.put(pNum, plist);
            }
            //距离判断，排查重复点
            if (Math.abs(point.getX() - pointLast.getX()) > 10 || Math.abs(point.getY() - pointLast.getY()) > 10) {
                pMap.get(pNum).add(point);
            }
        }
        //如果是抬笔
        if (pointLast.getPressure() > 0 && point.getPressure() == 0) {
            pMap.get(pNum).add(point);
            pNum++;
        }
        pointLast = point;
    }

    /**
     * 设置优化点默认笔的轨迹宽度
     */
    private void setOptimalPointWidth() {
        if (getPenServiceBinder() != null) {
            try {
                getPenServiceBinder().setPenPointWidth(mPenWeight);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        penTrajectoryView.initDrawArea();
        List<DataBaseBean> list = MyApplication.daoSession.getDataBaseBeanDao().loadAll();
        System.out.println(String.format("数据库内容：%d, %s", list.size(), list.toString()));
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (penTrajectoryView != null) {
            penTrajectoryView.cleanScreen();  // 清屏
            penTrajectoryView.dispose();
            penTrajectoryView = null;
        }
    }

    /**
     * 一般的抛出点方法
     * 此方法与 onRemoteOptimalPoint 方法只能使用其中的一个
     * 可以通过getPenServiceBinder().changeReportOptimalPoint(false)设置使用此方法
     */
    @Override
    public void onPenPositionChanged(int deviceType, int x, int y, int presure, byte state) {
        // state  00 离开 0x10悬空 0x11按下
        super.onPenPositionChanged(deviceType, x, y, presure, state);
        if (isRubber == 0) {// isRubber==0  现在没用橡皮察 止选择橡皮擦的时候，不小心触碰笔，绘制笔迹。
            DeviceType type = DeviceType.toDeviceType(deviceType);
            penTrajectoryView.drawDevicePoint(type, x, y, presure, state);
        }
    }

    /**
     * 带页码设备（如X10_B）点抛出方法
     */
    @Override
    public void onPenPointPositionChanged(int deviceType, float x, float y, int presure, byte state, long page) {
        super.onPenPointPositionChanged(deviceType, x, y, presure, state, page);
        if (isRubber == 0) {// isRubber==0  现在没用橡皮察 止选择橡皮擦的时候，不小心触碰笔，绘制笔迹。
            DeviceType type = DeviceType.toDeviceType(deviceType);
            penTrajectoryView.drawDevicePoint(type, (int) x, (int) y, presure, state);
        }
    }

    @Override
    public void onMatrixCustomPoint(int i, double v, double v1, int i1, int i2, int i3, int i4, int i5, String data) {
        Log.e(TAG, "onMatrixCustomPoint: " + v + "    " + v1 + "    " + i5);
    }

    @Override
    public void onOptimalMatrixCustomPoint(int i, double v, double v1, double v2, double v3, int i1, int i2, int i3, int i4, String data) {
        Log.e(TAG, "onOptimalMatrixCustomPoint: " + v + "    " + v1 + "    " + i4);
    }

    @Override
    public void onWritingDistanceChange(float v) {

    }

    @Override
    public void onRobotPenState(int i) {

    }

    @Override
    public void onMatrixOfflineInfo(int i, int i1, int i2, int i3) {

    }

    @Override
    public void onMatrixDataSyncStart(int i) {

    }

    @Override
    public void onMatrixDataSyncFinished(int i, List<BlockEntity> list, boolean b) {
        Log.v(TAG, "onMatrixDataSyncFinished:" + list.size());
    }

    @Override
    public void onMatrixDataDelFinished(int i) {

    }

    @Override
    public void onSetMatrixDecodeType(boolean b) {

    }

    @Override
    public void onGetMatrixCameraInfo(int i, int i1, int i2, int i3, int i4) {

    }

    @Override
    public void onTestRemoteDataSpeed(int i1, int i) {

    }

    /**
     * 笔服务连接状态回调
     * 成功不成功都调用
     *
     * @param name
     * @param service
     */
    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        super.onServiceConnected(name, service);
        checkDeviceConn();
        setOptimalPointWidth();
    }

    public void checkDeviceConn() {
        if (getPenServiceBinder() != null) {
            try {
                //设置点的抛出方式   默认为true
                // true   优化点抛出方法 --> onRemoteOptimalPoint
                // false  普通点抛出方法 --> 电磁笔：onPenPositionChanged   点阵笔：onPenPointPaperType
                getPenServiceBinder().changeReportOptimalPoint(false);
                RobotDevice device = getPenServiceBinder().getConnectedDevice();
                if (device != null) {
                    DeviceType type = DeviceType.toDeviceType(device.getDeviceVersion());
                    penTrajectoryView.setIsTouchWrite(false);
                    //判断当前设备与笔记设备是否一致
                    if (penTrajectoryView.getFrameSizeObject().getDeviceType() != type) {
                        mDeDeviceType = type;
                        mNoteKey = NoteEntity.KEY_NOTEKEY_TMP + "_" + mDeDeviceType.name();
                    }
                } else {
                    penTrajectoryView.setIsTouchWrite(true);
                }
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        } else {
            // penTrajectoryView.setIsTouchWrite(true);
        }
        //都需要刷新白板
        penTrajectoryView.initDrawArea();
    }

    @Override
    public void onStateChanged(int i, String s) {
        switch (i) {
            case RemoteState.STATE_CONNECTED:
                break;
            case RemoteState.STATE_DEVICE_INFO: //当出现设备切换时获取到新设备信息后执行的
                penTrajectoryView.setIsTouchWrite(false);// 设备连接成功，改为用笔输入
                checkDeviceConn();
                break;
            case RemoteState.STATE_DISCONNECTED://设备断开
                penTrajectoryView.setIsTouchWrite(true);// 设备断开，允许用手输入
                break;
        }

    }

    @Override
    public void onLargeOffLineNoteSyncFinished(String s, String s1) {

    }

    @Override
    public void onPenServiceError(String s) {

    }

    @Override
    public void onD7ReadPoint(int i, int i1, byte b) {

    }

    @Override
    public void onPageInfo(int i, int i1) {
        Log.d(TAG, String.format("onPageInfo %d, %d", i, i1));
    }

    @Override
    public void onWidthAndHeight(int i, int i1) {
        Log.d(TAG, String.format("onWidthAndHeight %d, %d", i, i1));
    }

    @Override
    public void onPageNumberAndCategory(long l, int i) {

    }

    @Override
    public void onPaperAngle(int i) {

    }

    @Override
    public void onSupportPenPressureCheck(boolean b) {

    }

    @Override
    public void onCheckPressureing() {

    }

    @Override
    public void onCheckPressurePen() {

    }

    @Override
    public void onCheckPressureFinish(int i) {

    }

    @Override
    public void onCheckModuleUpdate() {
    }

    @Override
    public void onCheckModuleUpdateFinish(byte[] bytes) {

    }

    @Override
    public void requetMemorySizeCallBack(int i) {

    }

    @Override
    public DeviceType getDeviceType() {
        return mDeDeviceType;
    }

    @Override
    public float getPenWeight() {
        return mPenWeight;
    }

    @Override
    public int getPenColor() {
        return mPenColor;
    }

    @Override
    public float getIsRubber() {
        return cb_rubber.isChecked() ? mPenWeight * 5 : isRubber;
    }

    @Override
    public float getIsPenRubber() {
        return cb_rubber.isChecked() ? mPenWeight : 0;
    }

    @Override
    public boolean getIsPressure() {
        return true;
    }

    @Override
    public void onTouchOutPoint(float x, float y, int presure, byte state, int color) {
        Log.d(TAG, "onTouchOutPoint: " + x + "," + y + "  P:" + presure + "   s:" + state + "  color:" + color);
    }

    @Override
    public boolean getIsHorizontal() {
        return isScreenLanscape();
    }

    @Override
    public boolean getIsOriginTopLeft() {
        return false;
    }

    public boolean isScreenLanscape() {
        Configuration mConfiguration = this.getResources().getConfiguration(); //获取设置的配置信息
        int ori = mConfiguration.orientation; //获取屏幕方向
        if (ori == mConfiguration.ORIENTATION_LANDSCAPE) {
            return true;//横屏
        } else if (ori == mConfiguration.ORIENTATION_PORTRAIT) {
            return false;//竖屏
        }
        return false;
    }

    @Override
    public boolean getUnlimitHorizontal() {
        return false;
    }

    @Override
    public long getCurrUserId() {
        return 0;
    }

    @Override
    public String getNoteKey() {
        return mNoteKey;
    }

    @Override
    public String getNewNoteName() { //修改右下角页码名称
        return "123";
    }

    @Override
    public boolean onMessage(String s, Object o) {
        return false;
    }

    @Override
    public void onPageInfoUpdated(String s) {

    }
}
